﻿<?php
	class Member{
	
		private $name;     //指标名,初始化时必须赋值
		private $id;
		private $profession;
		private $department;
		private $tel;
		private $tax;
		private $email;
		private $conn;
		
		function __construct(){
			$this->conn = conn();
		}	

		//输出当前情况下所对应Name,Id,Zone,FromDate,ToDate情况的列表
		public function listAll(){		
			$query = "select * from Member";
			$stmt = $this->conn->query( $query ); 
			$items = array();
			while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) { 
				$id = $row['ID'];
				$name = $row['name'];
				$profession = $row['profession'];
				$department = $row['department'];
				$tel = $row['tel'];
				$tax = $row['tax'];
				$email = $row['email'];
				$item=array("id"=>$id,"name"=>$name,"profession"=>$profession,"department"=>$department,
					"tel"=>$tel,"tax"=>$tax,"email"=>$email);
				array_push($items, $item);
			}				
			return $items;
		}
	
		public function deleteById($id){
			$query = "delete from Member where ID=".$id;
			$stmt = $this->conn->query( $query );
		}
		
		public function update($item){
			$id = $item['id'];
			$name = $item['name'];
			$profession = $item['profession'];
			$department = $item['department'];
			$tel = $item['tel'];
			$tax = $item['tax'];
			$email = $item['email'];
			$query = "update Member SET name ='".$name."', profession = '".$profession."', department = '".$department."'
				, tel = '".$tel."', tax='".$tax."', email='".$email."' where ID = '".$id."'";
			echo $query;
			$stmt = $this->conn->query( $query );
		}		
		
		public function insert($item){
			$id = $item['id'];
			$name = $item['name'];
			$profession = $item['profession'];
			$department = $item['department'];
			$tel = $item['tel'];
			$tax = $item['tax'];
			$email = $item['email'];	
			
			$query = "INSERT INTO Member(name,profession,department,tel,tax,email)
			VALUES('".$name."','".$profession."','".$department."','".$tel."','".$tax."','".$email."')";
			print_r ($query);
			$stmt = $this->conn->query( $query );
		}	
		
		public function delete($id){
			$query = "delete from Member where ID = '".$id."'";
			$stmt = $this->conn->query( $query );
		}
		
		public function getById($id){
			
			$query = "select * from Member where ID = '".$id."'";
			$stmt = $this->conn->query( $query );
			$row = $stmt->fetch( PDO::FETCH_ASSOC );
			$id = $row['ID'];
			$name = $row['name'];
			$profession = $row['profession'];
			$department = $row['department'];
			$tel = $row['tel'];
			$tax = $row['tax'];
			$email = $row['email'];
			$item=array("id"=>$id,"name"=>$name,"profession"=>$profession,"department"=>$department,
				"tel"=>$tel,"tax"=>$tax,"email"=>$email);
			return $item;			
		}
		
	}
?>